package uk.ac.manchester.cs.haphan.modbench;

import java.io.*;
import java.util.*;
import java.util.ArrayList;
import org.semanticweb.owlapi.apibinding.*;
import org.semanticweb.owlapi.model.*;
import org.semanticweb.owlapi.reasoner.*;
import org.semanticweb.owlapi.util.*;
import uk.ac.manchester.cs.factplusplus.owlapiv3.FaCTPlusPlusReasonerFactory;

public class Benchmarker {

    private String path;
    private ArrayList<String> entailmentFolders = new ArrayList<String>();
    private int i = 0;
    public Benchmarker(String path) {
        this.path = path;
    }

    public void start() {
        this.AddEntailmentFolder(this.path);
        for (String entFolder : this.entailmentFolders) {
            this.GetExpForEntailment(new File(entFolder));
        }

    }

    private void AddEntailmentFolder(String justPath) {
        File jDir = new File(justPath);

        for (File f : jDir.listFiles()) {
            if (f.isDirectory()) {
                System.out.println(f.getAbsolutePath());
                this.entailmentFolders.add(f.getAbsolutePath());
            }
        }
    }

    private void GetExpForEntailment(File oDir) {
        File ent = null;

        Set<File> explanations = new HashSet<File>();

        for (File owlFile : oDir.listFiles()) {
            if (owlFile.getName().contains("ax")) {
                //System.out.println("\nENTAILMENT: " + owlFile);
                ent = owlFile;
            } else if (owlFile.getName().contains("exp")) {
                explanations.add(owlFile);
            }
        }
        OWLOntology entOnt = null;
        OWLAxiom entailment = null;

        try {
            OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
            entOnt = manager.loadOntologyFromOntologyDocument(ent);
            
            for (OWLAxiom e : entOnt.getLogicalAxioms()) {
                entailment = e;

                System.out.println(i);

                
                ArrayList params = new ArrayList();
                params.add(e);
                params.add(explanations);
                params.add(i);
                //Runnable r = new BenchmarkWorker(params);
                //new Thread(r).start();
                //i++;
                //this.BenchmarkEntailment(entailment, explanations);
            }
        } catch (OWLOntologyCreationException e) {
            System.err.println(e.getMessage());
        }
    }
}
